package gaoyijiankao;

import cn.hutool.core.io.FileUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;

import java.util.*;

public class DataReader {

    public List<Map<String,Object>> readDatas(){
        ExcelReader reader= ExcelUtil.getReader(FileUtil.file("E:\\考试编排\\高一\\段考二考号编排.xls"), "段考一考号编排");
        List<Map<String,Object>> readAll = reader.readAll();
        return readAll;
    }

    public static void main(String[] args) {
        ArrayList<Map<String,Object>> datas= (ArrayList<Map<String, Object>>) new DataReader().readDatas();
        int shengwu=0;
        int dili=0;
        int huaxue=0;
        int zhengzhi=0;
        int lishi=0;
        int wuli=0;
        Iterator<Map<String,Object>> iterator=datas.iterator();
        while(iterator.hasNext()){
            Map<String,Object> data=iterator.next();
            String type= (String) data.get("类型");
            if(type.indexOf("历")!=-1){
                lishi++;
            }
            if(type.indexOf("物")!=-1){
                wuli++;
            }
            if(type.indexOf("生")!=-1){
                shengwu++;
            }
            if(type.indexOf("地")!=-1){
                dili++;
            }
            if(type.indexOf("化")!=-1){
                huaxue++;
            }
            if(type.indexOf("政")!=-1){
                zhengzhi++;
            }
        }
        System.out.println("选科生物："+shengwu+"人、地理："+dili+"人、化学："+huaxue
                +"人、政治："+zhengzhi+"人、历史："+lishi+"人、物理："+wuli+"人");

        BianPai.bianpai(datas,"E:\\考试编排\\高一\\段考二语数英试室安排表.xlsx","","ysy","语");
//        BianPai.bianpai(datas,"E:\\考试编排\\高一\\段考二历史试室安排表.xlsx","历史","lishi","历");
//        BianPai.bianpai(datas,"E:\\考试编排\\高一\\段考二物理试室安排表.xlsx","物理","wuli","物");
//        BianPai.bianpai(datas,"E:\\考试编排\\高一\\段考二政治试室安排表.xlsx","政治","zhengzhi","政");
//        BianPai.bianpai(datas,"E:\\考试编排\\高一\\段考二地理试室安排表.xlsx","地理","dili","地");
//        BianPai.bianpai(datas,"E:\\考试编排\\高一\\段考二生物试室安排表.xlsx","生物","shengwu","生");
//        BianPai.bianpai(datas,"E:\\考试编排\\高一\\段考二化学试室安排表.xlsx","化学","huaxue","化");

        Map<Integer,List<Map<String,Object>>> allResults=new HashMap<>();
        Collections.sort(datas,new SortRuler());
        for(Map<String,Object> data:datas){
            String xuehao= (String) data.get("学号").toString();
            int classNumber=Integer.parseInt(xuehao.substring(0,xuehao.length()-2));
            if(allResults.get(classNumber)==null){
                allResults.put(classNumber,new ArrayList<Map<String, Object>>());
            }
            Map<String,Object> result=new HashMap<>();
            result.put("学号",xuehao);
            result.put("姓名",data.get("姓名"));
            result.put("考生号",data.get("考生号"));
            result.put("考场",data.get("ysy"));
            allResults.get(classNumber).add(result);
        }

        for(Integer classNumber:allResults.keySet()){
//            System.out.println(classNumber);
            AllResultSheetForPrint allResultSheetForPrint=new AllResultSheetForPrint("E:\\考试编排\\高一\\高一(上)段考二考生号与试室安排(发班级).xlsx","高二"+classNumber+"班",4);
            allResultSheetForPrint.setTitle("2022届高一级（上）  段考二  考号及试室");
            allResultSheetForPrint.setFlags(new String[]{"学号","姓名","考生号","考场"});
            allResultSheetForPrint.setDatas(allResults.get(classNumber));
            allResultSheetForPrint.write();
        }
    }
}
